package zcj.stu;

import org.springframework.core.MethodParameter;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.method.support.ModelAndViewContainer;

import javax.servlet.http.HttpServletResponse;

public class ZcjLReturnValueHandler implements HandlerMethodReturnValueHandler {
    @Override
    public boolean supportsReturnType(MethodParameter methodParameter) {
        ZcjLanguage zcjLanguage = methodParameter.getMethodAnnotation(ZcjLanguage.class);
        return zcjLanguage!=null;
    }

    @Override
    public void handleReturnValue(Object returnValue, MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest) throws Exception {
        returnValue="->"+returnValue+"<-";
        HttpServletResponse response = nativeWebRequest.getNativeResponse(HttpServletResponse.class);
        response.setContentType("text/plain:charset=utf-8");
        response.getWriter().write(returnValue.toString());
        modelAndViewContainer.setRequestHandled(true);
    }
}
